// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_ok.java

package purchase.contact;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class check_ok extends HttpServlet
{

	public check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			nseer_db_backup1 purchase_db = new nseer_db_backup1(dbApplication);
			if (purchase_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				ValidataTag vt = new ValidataTag();
				String id = request.getParameter("id");
				String contact_ID = request.getParameter("contact_ID");
				String config_ID = request.getParameter("config_ID");
				String reason = request.getParameter("reason");
				String reasonexact = request.getParameter("reasonexact");
				String provider_ID = request.getParameter("provider_ID");
				String provider_name = request.getParameter("provider_name");
				String person_contacted = request.getParameter("person_contacted");
				String person_contacted_tel = request.getParameter("person_contacted_tel");
				String contact_person = request.getParameter("contact_person");
				String contact_person_ID = request.getParameter("contact_person_ID");
				String contact_time = request.getParameter("contact_time");
				String contact_type = request.getParameter("contact_type");
				String checker = request.getParameter("checker");
				String checker_ID = request.getParameter("checker_ID");
				String check_time = request.getParameter("check_time");
				String contact_content = new String(request.getParameter("contact_content").getBytes("UTF-8"), "UTF-8");
				String sql6 = (new StringBuilder("select id from purchase_workflow where object_ID='")).append(contact_ID).append("' and ((check_tag='0' and config_ID<'").append(config_ID).append("') or (check_tag='1' and config_ID='").append(config_ID).append("'))").toString();
				ResultSet rs6 = purchase_db.executeQuery(sql6);
				if (!rs6.next())
				{
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "purchase_contact", "contact_ID", contact_ID, "check_tag").equals("0"))
					{
						String sql = (new StringBuilder("update purchase_contact set contact_ID='")).append(contact_ID).append("',reason='").append(reason).append("',reasonexact='").append(reasonexact).append("',provider_ID='").append(provider_ID).append("',provider_name='").append(provider_name).append("',person_contacted='").append(person_contacted).append("',person_contacted_tel='").append(person_contacted_tel).append("',contact_person='").append(contact_person).append("',contact_person_ID='").append(contact_person_ID).append("',contact_time='").append(contact_time).append("',contact_type='").append(contact_type).append("',contact_content='").append(contact_content).append("',checker='").append(checker).append("',checker_ID='").append(checker_ID).append("',check_time='").append(check_time).append("' where id=").append(id).toString();
						purchase_db.executeUpdate(sql);
						String sql9 = (new StringBuilder("update purchase_workflow set checker='")).append(checker).append("',checker_ID='").append(checker_ID).append("',check_time='").append(check_time).append("',check_tag='1' where object_ID='").append(contact_ID).append("' and config_ID='").append(config_ID).append("'").toString();
						purchase_db.executeUpdate(sql9);
						sql9 = (new StringBuilder("select id from purchase_workflow where object_ID='")).append(contact_ID).append("' and check_tag='0'").toString();
						ResultSet rset = purchase_db.executeQuery(sql9);
						if (!rset.next())
						{
							sql9 = (new StringBuilder("update purchase_contact set reason='")).append(reason).append("',check_tag='1' where contact_ID='").append(contact_ID).append("'").toString();
							purchase_db.executeUpdate(sql9);
							int contact_amount = 0;
							String sql3 = (new StringBuilder("select * from purchase_file where provider_ID='")).append(provider_ID).append("'").toString();
							ResultSet rs3 = purchase_db.executeQuery(sql3);
							if (rs3.next())
								contact_amount = rs3.getInt("contact_amount") + 1;
							String sql4 = (new StringBuilder("update purchase_file set contact_amount='")).append(contact_amount).append("',lately_contact_time='").append(check_time).append("',remind_contact_tag='0' where provider_ID='").append(provider_ID).append("'").toString();
							purchase_db.executeUpdate(sql4);
						} else
						{
							sql9 = (new StringBuilder("update purchase_contact set reason='")).append(reason).append("' where contact_ID='").append(contact_ID).append("'").toString();
							purchase_db.executeUpdate(sql9);
						}
						response.sendRedirect("purchase/contact/check_ok.jsp?finished_tag=0");
					} else
					{
						response.sendRedirect("purchase/contact/check_ok.jsp?finished_tag=1");
					}
				} else
				{
					response.sendRedirect("purchase/contact/check_ok.jsp?finished_tag=2");
				}
				purchase_db.commit();
				purchase_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
